package com.wb.mianxiangduixiang.银行管理系统;

import java.util.Scanner;

/**
 * @author 黄衡熙
 * @version 1.0
 * @date 2025年07月22日15:14
 */
public class Start {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        new Start().showMenu();
    }
   public void showMenu() {
        System.out.println("****************欢迎来到紫金银行系统****************");
        System.out.print("请输入您的需求:1.开户  2.登录:");
        int choice = sc.nextInt();
        switch (choice) {
            case 1:
                register();
                break;
            case 2:
                login();
                break;
            default:
                System.out.println("您输入的选项有误，已退出系统");
        }
    }
    public void register() {
        System.out.print("请选择开户的账户类型(1.储蓄账户 2.信用账户 3.贷款的储蓄账户 4.贷款的信用账户):");
        int choice = sc.nextInt();
        switch(choice){
            case 1:
                Account account=new SavingAccount();
                break;
            case 2:
                account=new CreditAccount();
                break;
            case 3:
                account=new LoanSavingAccount();
                break;
            case 4:
                account=new LoanCreditAccount();
                break;
            default:
                System.out.println("您输入的选项有误，已退出系统");
                return;


        }

        Account account = new SavingAccount();
        // 填写开户所需要的信息
        System.out.print("请输入户主姓名:");
        String name = sc.next();
        account.setName(name);
        //System.out.println();
        System.out.print("请输入账户密码:");
        String password = sc.next();
        account.setPassword(password);
        System.out.print("请输入身份证号码:");
        String personId = sc.next();
        account.setPersonId(personId);
        System.out.print("请输入预留手机号码:");
        String phone=sc.next();
        account.setPhone(phone);
        // 当所有信息全部填写完成之后,调用银行提供的开户功能进行开户
        Bank.register(account);
        System.out.println("您的卡号为:"+account.getId()+"恭喜您，开户成功！");

        // 当开户成功之后回到入口程序主菜单,继续选择其他服务
        this.showMenu();

    }
    public void login() {
        System.out.print("请输入卡号:");
        int id = sc.nextInt();
        System.out.print("请输入密码:");
        String password = sc.next();
        // 根据银行Bank提供的登录方法判断当前输入的卡号与密码是否正确
        Account account = Bank.login(id, password);
        if (account == null) {
            // 如果返回值为null,说明卡号或者密码有误
            System.out.println("卡号或者密码错误，请重新输入!");
            this.login();
        } else {
            // 否则,登录成功,进入到银行主菜单
            BankMenu menu = new BankMenu();
            menu.showMeun();
        }

    }

}
